<include file="public@header"/>
<style>

    .districts-width{
        width:150px;
    }

</style>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a>所有群组</a></li>
        <li><a href="{:url('/company/admin_member_group/add')}">群组添加</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('/company/admin_member_group/index')}">
        <div class="form-group">
        所在地区

            <select class="form-control" id="province" name="post[province_id]" >
                <php>$select = $districts['options'][0]['id'] == 0 ? "selected" : "";</php>
                <option value="" {$select} data-text="">请选择</option>
                <foreach name="districts['options'][0]['options']" item="vo">
                    <php>

                        $select = (empty($_REQUEST['post']['province_id'])?"0":$_REQUEST['post']['province_id']) == $vo['id'] ? "selected" : "";

                    </php>
                    <option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
                </foreach>
            </select>


            <select class="form-control" id="city" name="post[city_id]" >
                <php>$select = $districts['options'][1]['id'] == 0 ? "selected" : "";</php>
                <option value="" {$select} data-text="">请选择</option>
                <foreach name="districts['options'][1]['options']" item="vo">
                    <php>$select = $districts['options'][1]['id'] == $vo['id'] ? "selected" : "";</php>
                    <option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
                </foreach>
            </select>


            <select class="form-control" id="country" name="post[country_id]" >
                <php>$select = $districts['options'][2]['id'] == 0 ? "selected" : "";</php>
                <option value="" {$select} data-text="">请选择</option>
                <foreach name="districts['options'][2]['options']" item="vo">
                    <php>$select = $districts['options'][2]['id'] == $vo['id'] ? "selected" : "";</php>
                    <option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
                </foreach>
            </select>



        关键字：
        <input class="form-control" type="text" name="post[name]" style="width: 200px;" value="{:input('request.post.name')}"
               placeholder="标题\关键字">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('/company/admin_member_group/index')}">清空</a>

        </div>
    </form>
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>序号</th>
                <th>名称</th>
                <th>人数</th>
                <th>成立时间</th>
                <th>所在地区</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            <foreach name="qa_list" item="vo" key="k">
                <tr>
                    <td>{$k+1}</td>
                    <td>{$vo['name']}
                    </td>
                    <td>{$vo.person_count}</td>
                    <td>{:date('Y-m-d',$vo['create_date'])}</td>
                    <td>{$vo['district_name']}</td>
                    <td>
                        <a href="{:url('/company/admin_member_group/edit',array('id'=>$vo['id']))}" >修改</a>
                        <a href="{:url('/company/admin_member_group/delete',array('id'=>$vo['id']))}"  class="js-ajax-delete">删除</a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
        <div class="pagination">{$page}</div>
</div>



<link rel="stylesheet" href="__STATIC__/js/select2/css/select2.min.css">

<script src="__STATIC__/js/select2/js/select2pinyin.js?v=201802271547"></script>

<script>

    $(function () {
        var $province = $("#province");
        var $city = $("#city");
        var $country = $("#country");
        var $district_id = $("#district_id");
        var $district_name = $("#district_name");

        var empty = "<option value='' data-text=''>请选择</option>";

        $province.select2({
            width: "150px", //设置下拉框的宽度
        });
        $city.select2({
            width: "150px", //设置下拉框的宽度
        });
        $country.select2({
            width: "150px", //设置下拉框的宽度
        });

        $province.on('change', function () {
            var province = $province.find("option:selected");
            if (province.val().length == 0) {
                $city.html(empty);
                $country.html(empty);
                $district_id.val(0);
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: province.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $city.html(options);
                    $country.html(empty);
                });
                $district_id.val(province.val());
            }
            $district_name.val(province.data("text"));
        });
        $city.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            if (city.val().length == 0) {
                $country.html(empty);
                $district_id.val(province.val());
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: city.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $country.html(options);
                });
                $district_id.val($city.val());
            }
            $district_name.val(province.data("text") + city.data("text"));
        });
        $country.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            var country = $country.find("option:selected");
            if (country.val().length == 0) {
                $district_id.val(city.val());
            } else {

                $district_id.val(country.val());
            }
            $district_name.val(province.data("text") + city.data("text") + country.data("text"));
        });


    })
</script>

<script src="__STATIC__/js/admin.js"></script>

<script >

    function openapp(url,win,title) {
        parent.openapp(url,win,title);
    }

</script>
</body>
</html>